using System;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TTQT.TTQT_Code;

/// <summary>
/// Summary description for KhoAnChi_Mau
/// </summary>
public class KhoAnChi_Mau
{
    private string ConnectionString;
    public KhoAnChi_Mau()
    {
        ConnectionString = TTQTCommon.DBConnectionString;
    }
    
    public KhoAnChi_Mau(string ConnStr)
    {
        ConnectionString = TTQTCommon.DBConnectionString;
    }

    private string m_id;
    public string id
    {
        get { return m_id; }
        set { m_id = value; }
    }
    private string m_NgayKhaiBao;
    public string NgayKhaiBao
    {
        get { return m_NgayKhaiBao; }
        set { m_NgayKhaiBao = value; }
    }
    private string m_NgayCapNhat;
    public string NgayCapNhat
    {
        get { return m_NgayCapNhat; }
        set { m_NgayCapNhat = value; }
    }
    private string m_Ma;
    public string Ma
    {
        get { return m_Ma; }
        set { m_Ma = value; }
    }
    private string m_TenAnChi;
    public string TenAnChi
    {
        get { return m_TenAnChi; }
        set { m_TenAnChi = value; }
    }
    private string m_Seri;
    public string Seri
    {
        get { return m_Seri; }
        set { m_Seri = value; }
    }
    private string m_MenhGia;
    public string MenhGia
    {
        get { return m_MenhGia; }
        set { m_MenhGia = value; }
    }
    private string m_SoLuong;
    public string SoLuong
    {
        get { return m_SoLuong; }
        set { m_SoLuong = value; }
    }
    private string m_LoaiTien;
    public string LoaiTien
    {
        get { return m_LoaiTien; }
        set { m_LoaiTien = value; }
    }
    private string m_Brn_Code;
    public string Brn_Code
    {
        get { return m_Brn_Code; }
        set { m_Brn_Code = value; }
    }
    private string m_User_Name;
    public string User_Name
    {
        get { return m_User_Name; }
        set { m_User_Name = value; }
    }

    public void Update(string id, string NgayKhaiBao, string NgayCapNhat, string Ma, string TenAnChi, string Seri, string MenhGia, string SoLuong, string LoaiTien, string Brn_Code, string User_Name)
		{
        SqlConnection conn = new SqlConnection(ConnectionString);
			SqlCommand cmd = new SqlCommand("Update_KhoAnChi_Mau", conn);
			cmd.CommandType = CommandType.StoredProcedure;
			cmd.Parameters.AddWithValue(@"id" ,id );
			cmd.Parameters.AddWithValue(@"NgayKhaiBao" ,NgayKhaiBao );
			cmd.Parameters.AddWithValue(@"NgayCapNhat" ,NgayCapNhat );
			cmd.Parameters.AddWithValue(@"Ma" ,Ma );
			cmd.Parameters.AddWithValue(@"TenAnChi" ,TenAnChi );
			cmd.Parameters.AddWithValue(@"Seri" ,Seri );
			cmd.Parameters.AddWithValue(@"MenhGia" ,MenhGia );
			cmd.Parameters.AddWithValue(@"SoLuong" ,SoLuong );
			cmd.Parameters.AddWithValue(@"LoaiTien" ,LoaiTien );
			cmd.Parameters.AddWithValue(@"Brn_Code" ,Brn_Code );
			cmd.Parameters.AddWithValue(@"User_Name" ,User_Name );

			try
			{
				conn.Open();
				cmd.ExecuteNonQuery();
			}
			catch
			{}
			finally
			{
				if (conn.State == ConnectionState.Open) conn.Close();
				conn.Dispose();
				cmd.Dispose();
			}
		}

    public void Insert()
		{
            SqlConnection conn = new SqlConnection(ConnectionString);
			SqlCommand cmd = new SqlCommand("Insert_KhoAnChi_Mau", conn);
			cmd.CommandType = CommandType.StoredProcedure;
			cmd.Parameters.AddWithValue("@Ma" ,Ma );
			cmd.Parameters.AddWithValue("@TenAnChi" ,TenAnChi );
			cmd.Parameters.AddWithValue("@Seri" ,Seri );
			cmd.Parameters.AddWithValue("@MenhGia" ,MenhGia );
			cmd.Parameters.AddWithValue("@SoLuong" ,SoLuong );
			cmd.Parameters.AddWithValue("@LoaiTien" ,LoaiTien );
			cmd.Parameters.AddWithValue("@Brn_Code" ,Brn_Code );
			cmd.Parameters.AddWithValue("@User_Name" ,User_Name );

			try
			{
				conn.Open();
				cmd.ExecuteNonQuery();
			}
			catch(Exception ex)
			{
			    string error = ex.ToString();
			}
			finally
			{
				if (conn.State == ConnectionState.Open) conn.Close();
				conn.Dispose();
				cmd.Dispose();
			}
		}

    public void Delete(string ID)
		{
            SqlConnection conn = new SqlConnection(ConnectionString);
			SqlCommand cmd = new SqlCommand("Delete_KhoAnChi_Mau", conn);
			cmd.CommandType = CommandType.StoredProcedure;
			cmd.Parameters.AddWithValue("@ID",ID);

			try
			{
				conn.Open();
				cmd.ExecuteNonQuery();
			}
			catch
			{}
			finally
			{
				if (conn.State == ConnectionState.Open) conn.Close();
				conn.Dispose();
				cmd.Dispose();
			}
		}

    public DataSet SelectRecords()
		{
            SqlConnection conn = new SqlConnection(ConnectionString);
			SqlDataAdapter cmd = new SqlDataAdapter("SELECT * FROM Select_KhoAnChi_Mau", conn);
			DataSet dts = new DataSet();
			try
			{
				conn.Open();
				cmd.Fill(dts);
				return dts;
			}
			catch
			{ }
			finally
			{
				if (conn.State == ConnectionState.Open) conn.Close();
				cmd.Dispose();
			}
			return dts;
		}
}
